 package vista;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Timer;

import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.LayoutStyle;
import javax.swing.UIManager;
import vista.VistaJuego;
import modelo.MdJuego;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class VentanaPrincipalJuego extends javax.swing.JFrame {

    /** Creates new form Principal */
	String jugador;
    public VentanaPrincipalJuego(int nroMinasAlto , int nroMinasAncho, int nroMinas) {
    	jugador = JOptionPane.showInputDialog("Como te llamas amigo?");
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) {
            e.printStackTrace();
        }
        panelBuscaminas1 = new MdJuego(nroMinasAlto, nroMinasAncho, nroMinas);
        panelBuscaminas1.setJug(jugador);
        initComponents();
        
        panelBuscaminas1.cargarcampoMinado();
        setSize(500, 500);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void correrTiempo()
    {
           timer = new Timer (1000, new ActionListener ()
            {
                public void actionPerformed(ActionEvent e)
                {
                	tiempo++;            
                //	System.out.println(tiempo);
                	titulo();
                }
                
            });
           
            
       timer.start();
    }
    void titulo()
    {
    	this.setTitle("Tiempo de "+jugador+" : "+tiempo);
    	
    }
    


	private void initComponents() {
        
        
        jButton1 = new javax.swing.JButton();
        tiempo=0;
        correrTiempo();
        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        panelBuscaminas1.setBackground(new java.awt.Color(192,192,192));

        javax.swing.GroupLayout panelBuscaminas1Layout = new javax.swing.GroupLayout(panelBuscaminas1);
        panelBuscaminas1.setLayout(panelBuscaminas1Layout);
        panelBuscaminas1Layout.setHorizontalGroup(
            panelBuscaminas1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 505, Short.MAX_VALUE)
        );
        panelBuscaminas1Layout.setVerticalGroup(
            panelBuscaminas1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 288, Short.MAX_VALUE)
        );
        jButton1.setText("Nuevo Juego");
        jButton1.setFocusable(false);
        jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setVerticalGroup(layout.createSequentialGroup()
        	.addComponent(jButton1, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE)
        	.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 1, GroupLayout.PREFERRED_SIZE)
        	.addComponent(panelBuscaminas1, GroupLayout.PREFERRED_SIZE, 419, GroupLayout.PREFERRED_SIZE));
        layout.setHorizontalGroup(layout.createParallelGroup()
        	.addComponent(panelBuscaminas1, GroupLayout.Alignment.LEADING, 0, 484, Short.MAX_VALUE)
        	.addComponent(jButton1, GroupLayout.Alignment.LEADING, 0, 484, Short.MAX_VALUE));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    	tiempo=0;
        panelBuscaminas1.cargarcampoMinado(); 
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    //import modelo.Buscaminas;
    private javax.swing.JButton jButton1;
    private MdJuego panelBuscaminas1;
    public int getTiempo() {
		return tiempo;
	}

	private Timer timer;
    private int tiempo;
    
    // End of variables declaration//GEN-END:variables
}

/*import controlador.ControladorVentanaRegitrarJugador;
import controlador.ControladorVentanaMenu;
 public class PrincipalJuego{
	   
	public static void main(String[] args) {
		new ControladorVentanaMenu();
	}
 }
		/* java.awt.EventQueue.invokeLater(new Runnable() {

	            public void run() {
	                new PrincipalJuego().setVisible(true);
	            }
	        });

		//new ControladorVentanaPrincipal();

	}

}
*/